package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Mr.bilal
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {

    @Autowired
    BorrowerService borrowerService;

    @GetMapping("/getBorrowerStatusByUserId")
    public R getBorrowerStatusByUserId(HttpServletRequest request){
        String userId = request.getHeader("userId");
        Integer BorrowerStatus =  borrowerService.getBorrowerStatusByUserId(userId);
        return  R.ok().data("borrowerStatus",BorrowerStatus);
    }

    @PostMapping("/save")
    public R saveBorrower(@RequestBody BorrowerVO borrowerVO,HttpServletRequest request){
        String userId = request.getHeader("userId");
        borrowerService.saveBorrower(borrowerVO,userId);
        return R.ok().data("borrowerVO",borrowerVO);
    }
}

